import Vue from 'vue'
import axios from 'axios'
import superMallCommons from '../commons'

/**
 * 创建与后台交互的参数对象
 * @param module
 * @returns {Object}
 */
const createBaseRequestParamData = function (module) {
  let obj = new Object()
  obj.time = new Date().getTime()
  obj.module = module
  obj.appId = '111111'
  obj.appKey = 'abcdefg'

  obj.token = localStorage.getItem(superMallCommons.consts.sessionKeys.JWT_TOKEN)
  return obj
}
const createSupermallReqParamData = function (data) {
  let obj = createBaseRequestParamData('supermall')
  obj.data = data
  return obj
}
Vue.prototype.$createReqParamData = createSupermallReqParamData

/**
 * 不带任何前缀地址
 * @type {AxiosInstance}
 */
Vue.prototype.simpleAxios = axios.create({
  timeout: 30000,
  headers: { 'Content-Type': 'application/json' },
  withCredentials: false
})
/**
 * 后台服务
 * @type {AxiosInstance}
 */
const axiosInstance = axios.create({
  // baseURL: process.env.VUE_APP_SUPERMALL_API_BASEURL,
  baseURL: 'http://60.221.62.216:1111',
  timeout: 30000,
  headers: { 'Content-Type': 'application/json' },
  withCredentials: false
})
Vue.prototype.$axios_supermall = axiosInstance

export { createSupermallReqParamData, axiosInstance }
